home *** CD-ROM | disk | FTP | other *** search
- # this program will merge new MailShield config files
- # with old ones. The settings from the old files are
- # read in, along with the help description from the
- # new files, and this is written out to the new directory.
-
- # parses out the information from a single config file
- proc fix_file { file old_dir new_dir dest_dir } {
-
- #puts "\rProcessing $file"
-
- set old_help {}
- set old_value {}
- set new_help {}
- set new_value {}
-
- if { [file exists "$old_dir/$file"] } {
-
- SplitHelpValueForFile "$old_dir/$file" old_help old_value
- SplitHelpValueForFile "$new_dir/$file" new_help new_value
-
- set dest_file [open "$dest_dir/$file" w]
- puts $dest_file $new_help
- puts $dest_file $old_value
- close $dest_file
- } else {
- # if the old file doesn't exist, then just copy it to the destination directory
- catch { file copy "$new_dir/$file" "$dest_dir/$file" }
- }
-
- }
-
-
- proc SplitHelpValueForFile { file help value } {
- upvar $help this_help
- upvar $value this_value
-
- set thistext [ReadEntireFile "$file"]
-
- set in_help 1
-
- foreach temp_line [split $thistext \n] {
- if {[string index $temp_line 0] != "#"} {
- set in_help 0
- }
-
- if {$in_help == 1} {
- append this_help "$temp_line\n"
- #puts "H: $temp_line"
- } else {
- if { [string length $temp_line] > 0 } {
- append this_value "$temp_line\n"
- #puts "V: $temp_line"
- }
- }
- }
-
- set this_value [string trim $this_value]
- set this_help [string trim $this_help]
- }
-
- # fills the global variables with the parsed values of all the config files
- proc FixAllfiles { old_dir new_dir dest_dir } {
- puts "Upgrading config files from $old_dir to $new_dir, writing to $dest_dir";
- set sh_config_files [GetFilesForDir $new_dir]
-
- foreach configfile $sh_config_files {
- fix_file $configfile $old_dir $new_dir $dest_dir
- }
- puts "Success!";
- }
-
- # given a directory name, returns a list of files in that directory
- proc GetFilesForDir { dirname } {
- set old_dir [pwd]
- cd $dirname
- set retval [glob -nocomplain *]
- cd $old_dir
- return $retval
- }
-
- # read the entire contents of a file into memory and returns it
- proc ReadEntireFile { filename } {
- #puts "reading file: $filename"
- set file_text ""
- catch {
- set file_id [open $filename RDONLY]
- set file_text [read $file_id]
- close $file_id
- }
- return $file_text
- }
-
- proc RemoveFile { remove_file keep_file dir } {
-
- # split the old and new files into help and data
- set remove_help {}
- set remove_value {}
- set keep_help {}
- set keep_value {}
-
- if { [file exists "$dir/$remove_file"] && \
- [file exists "$dir/$keep_file"] } {
-
- SplitHelpValueForFile "$dir/$remove_file" remove_help remove_value
- SplitHelpValueForFile "$dir/$keep_file" keep_help keep_value
-
- set merge_file [open "$dir/$keep_file" w]
- puts $merge_file $keep_help
- puts $merge_file $keep_value
- puts $merge_file $remove_value
- close $merge_file
- }
-
- }
-
- proc main {} {
-
- puts "Working in: [pwd]"
- #puts "Argv: $argv"
-
- #set old_dir "../config1"
- #set new_dir "../config2"
- #set dest_dir "../config3"
-
- set old_dir "cfgold"
- set new_dir "config"
- set dest_dir "config"
-
- # enumerate the files that have been reduced.
- # a "reduction" means that some feature has been outmoded and it's
- # function has been taken over by a "new" feature.
- #
- # thus, the data from the old feature must be included as part of
- # the data in the "new" feature.
- #
- # format for array: index -> outmoded file
- # value -> 'new' file
- #
-
- array set remove [list banbody.txt bantext.txt]
-
- # perform reductions on any files that may need it.
-
- foreach old [array names remove] {
- RemoveFile $old $remove($old) $old_dir
- }
-
- FixAllfiles $old_dir $new_dir $dest_dir
- }
-
- main
-